package com.chb.microservice.provider.hystrix;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cbh.api.model.ApiResult;
import com.chb.microservice.provider.feign.InsuranceCompanyFeignClient;
import com.chb.microservice.provider.model.InsuranceCompany;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class InsuranceCompanyHystrixWrapped {

	@Autowired
	private InsuranceCompanyFeignClient insuranceCompanyFeignClient;

	/**
	 * 新增保险公司
	 * 
	 * @param icId
	 * @param icCode
	 * @param icName
	 * @param icDetail
	 * @param icLogo
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<String> save(String icId, String icCode, String icName, String icDetail, String icLogo) {
		return insuranceCompanyFeignClient.save(icId, icCode, icName, icDetail, icLogo);
	}

	public ApiResult<String> fallBackCall(String icId, String icCode, String icName, String icDetail, String icLogo) {
		return new ApiResult<String>().fail("调用出错");
	}

	/**
	 * 根据Code获取保险公司信息
	 * 
	 * @param icCode
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall2")
	public ApiResult<InsuranceCompany> getByIcCode(String code) {
		return insuranceCompanyFeignClient.getByIcCode(code);
	}

	public ApiResult<InsuranceCompany> fallBackCall2(String code) {
		return new ApiResult<InsuranceCompany>().fail("调用出错");
	}

	/**
	 * 根据ID获取保险公司信息
	 * 
	 * @param id
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall3")
	public ApiResult<InsuranceCompany> getByIcId(String id) {
		return insuranceCompanyFeignClient.getByIcId(id);
	}
	public ApiResult<InsuranceCompany> fallBackCall3(String id) {
		return new ApiResult<InsuranceCompany>().fail("调用出错");
	}
	/**
	 * 根据ID删除保险公司信息
	 * 
	 * @param icId
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall4")
	public ApiResult<Boolean> deleteByIcId(String id) {
		return insuranceCompanyFeignClient.deleteByIcId(id);
	}

	public ApiResult<Boolean> fallBackCall4(String id) {
		return new ApiResult<Boolean>().fail("调用出错");
	}

	/**
	 * 获取全部保险公司信息
	 * 
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall5")
	public ApiResult<List<InsuranceCompany>> getAll() {
		return insuranceCompanyFeignClient.getAll();
	}

	public ApiResult<List<InsuranceCompany>> fallBackCall5() {
		return new ApiResult<List<InsuranceCompany>>().fail("调用出错");
	}
}
